import axiosInstance from "@/utils/request";
import {list} from "postcss";

/**
 * 用户基础信息地址
 */
enum Api {
    BASE_URL = '/user/base/info',
    QUERY_USER_BASE_INFO_BY_TOKEN = `${BASE_URL}/queryUserBaseInfoByToken`,
    PAGE = `${BASE_URL}/page`,
    ADMIN_ADD_USER_BASE_INFO = `${BASE_URL}/adminAddUserBaseInfo`,
    ADMIN_UPDATE_USER_BASE_INFO = `${BASE_URL}/adminUpdateUserBaseInfo`,
    DELETE_BY_ID = `${BASE_URL}/delete`,
    DELETE_BY_IDS = `${BASE_URL}/deleteBatchByIds`,
    SEARCH_BY_CONDITION = `${BASE_URL}/searchByCondition`,
}

export interface Page<T> {
    pageNumber: number
    pageSize: number
    records: T[]
    totalPage: number
    totalRow: number
}

export interface Records {
    id: string
    createTime: string
    updateTime: string
    createUser: string
    updateUser: string
    name: string
    nickName?: string
    sex?: string
    age?: string
    email?: string
    phone?: string
    birthday?: string
    address: string
    avatar?: string
    description?: string
    userRoleJoinRoleDtoList?: []
}

/**
 * 根据token获取用户基本信息
 */
export const queryUserBaseInfoByToken = () => {
    return axiosInstance({
        url: Api.QUERY_USER_BASE_INFO_BY_TOKEN,
        method: 'get',
    })
}

/**
 * 分页查询用户信息
 * @param pageNum 第几页
 * @param pageSize 每页多少条
 */
export const page = (pageNum: number, pageSize: number) => {
    return axiosInstance({
        url: `${Api.PAGE}/${pageNum}/${pageSize}`,
        method: 'get',
    })
}

/**
 * 管理员修改用户基本信息
 * @param data 用户基本信息
 */
export const adminAddUserBaseInfo = (data: any) => {
    return axiosInstance({
        url: Api.ADMIN_ADD_USER_BASE_INFO,
        method: 'post',
        data: data
    })
}

/**
 * 管理员修改用户基本信息
 * @param data 用户基本信息
 */
export const adminUpdateUserBaseInfo = (data: any) => {
    return axiosInstance({
        url: Api.ADMIN_UPDATE_USER_BASE_INFO,
        method: 'post',
        data: data
    })
}

/**
 * 批量删除用户基本信息
 * @param id 用户id
 */
export const deleteById = (id: string) => {
    return axiosInstance({
        url: `${Api.DELETE_BY_ID}/${id}`,
        method: 'get',
    })
}

/**
 * 批量删除用户基本信息
 * @param ids 用户id数组
 */
export const deleteByIds = (ids: []) => {
    return axiosInstance({
        url: Api.DELETE_BY_IDS,
        method: 'post',
        data: ids
    })
}

/**
 * 根据条件查询用户基本信息
 * @param data 查询条件
 */
export const searchByCondition = (data: any) => {
    return axiosInstance({
        url: Api.SEARCH_BY_CONDITION,
        method: 'post',
        data: data
    })
}
